﻿//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0           ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NetCMS.Content;

public partial class manage_channel_ChannelLabelList : NetCMS.Web.UI.ManagePage
{
    Channel rd = new Channel();
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.CacheControl = "no-cache";
        this.PageNavigator1.OnPageChange += new PageChangeHandler(PageNavigator1_PageChange);
        if (!IsPostBack)                                                        //判断页面是否重载
        {
            int GChID = 0;
            string ChID = Request.QueryString["ChID"];
            if (ChID != string.Empty && ChID != null)
            {
                GChID = int.Parse(ChID.ToString());
            }
            GetChID(this.gChID, GChID,0,0);
            StartLoad(1, GChID);
        }
    }

    protected void PageNavigator1_PageChange(object sender, int PageIndex)
    {
        int GChID = 0;
        string ChID = Request.QueryString["ChID"];
        if (ChID != string.Empty && ChID != null)
        {
            GChID = int.Parse(ChID.ToString());
        }
        StartLoad(PageIndex, GChID);
    }


    //数据初始化
    protected void StartLoad(int PageIndex, int ChID)
    {
        int i, j;
        DataTable dt = rd.GetSLabelPage(ChID,PageIndex, 50, out i, out j, null);
        this.PageNavigator1.PageCount = j;
        this.PageNavigator1.PageIndex = PageIndex;
        this.PageNavigator1.RecordCount = i;
        string strchar = string.Empty;
        string PoPstr = string.Empty;
        if (dt != null && dt.Rows.Count > 0)
        {
            dt.Columns.Add("GstyleName", typeof(string));
            for (int k = 0; k < dt.Rows.Count; k++)
            {
                dt.Rows[k]["GstyleName"] = "<li><nobr><a class=\"list_link\" href=\"###\" onclick=\"selectLabel('{NT_CH$" + dt.Rows[k]["ChID"].ToString() + "_" + dt.Rows[k]["LabelName"].ToString() + "}')\" title=\"点击选择\">" + dt.Rows[k]["LabelName"].ToString() + "</a></li>";
            }
        }
        DataList1.DataSource = dt;
        DataList1.DataBind();
        dt.Clear(); dt.Dispose();
    }

    public void GetChID(DropDownList lst, int ChID,int ParentID,int Layer)
    {
        IDataReader dr = rd.getModelTemplet(ParentID);
        int i = 1;
        while (dr.Read())
        {
            string stxt = "";
            if (Layer > 0)
            {
                stxt = "┞┄ ";
            }
            ListItem it = new ListItem();
            it.Value = dr["ID"].ToString();
            it.Text = stxt + dr["channelName"].ToString();
            if (ChID == int.Parse(dr["id"].ToString()))
            {
                it.Selected = true;
            }
            lst.Items.Add(it);
            i++;
            GetChID(lst, ChID, int.Parse(dr["ID"].ToString()), Layer + 1);
        }
        dr.Close();
    }
}
